using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVRKOPF
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "TST":
                default:
                    #region=========
                    dwReturn["VRKMANDANT"] = app.Mandant;
                    dwReturn["VRKRENR"] = "00000000";
                    dwReturn["VRKAENZL"] = "0";
                    dwReturn["VRKAENB"] = "        ";
                    dwReturn["VRKAEND"] = "0";
                    dwReturn["VRKNEUB"] = "        ";
                    dwReturn["VRKNEUD"] = "0";
                    dwReturn["VRKKUNDNR"] = "00000000";
                    dwReturn["VRKADRSL"] = "        ";
                    dwReturn["VRKREART"] = "SR";
                    dwReturn["VRKREDAT"] = "0";
                    dwReturn["VRKZAHLBED"] = "   ";
                    dwReturn["VRKVALUTA"] = "0";
                    dwReturn["VRKVALDAT"] = "0";
                    dwReturn["VRKWAEHRSL"] = "RMB";
                    dwReturn["VRKKURS"] = "10000";
                    dwReturn["VRKBETRAG"] = "1";
                    dwReturn["VRKWAWERT"] = "0";
                    dwReturn["VRKFRACHT"] = "0";
                    dwReturn["VRKVERSICH"] = "0";
                    dwReturn["VRKVERPKO"] = "0";
                    dwReturn["VRKZUAB"] = "0";
                    dwReturn["VRKGESWERTN"] = "0";
                    dwReturn["VRKMWST"] = "0";
                    dwReturn["VRKGESWERTB"] = "0";
                    dwReturn["VRKEKON"] = "        ";
                    dwReturn["VRKFIBUDAT"] = "0";
                    dwReturn["VRKFIBUBELEG"] = "0";
                    dwReturn["VRKFIBUKZ"] = "N";
                    dwReturn["VRKZAHLDAT"] = "0";
                    dwReturn["VRKZAHLBTR"] = "0";
                    dwReturn["VRKKOMPL"] = "N";
                    dwReturn["VRKFAELLIG"] = "0";
                    dwReturn["VRKVB"] = "2  ";
                    dwReturn["VRKSTUFE"] = " ";
                    dwReturn["VRKAUFTYP"] = "K";
                    dwReturn["VRKKZINLEXP"] = "E";
                    dwReturn["VRKLPOS"] = "000";
                    dwReturn["VRKDRKZ"] = " ";
                    dwReturn["VRKUMSATZ"] = "N";
                    dwReturn["VRKKUNDNRVK"] = "        ";
                    dwReturn["VRKADRSLVK"] = "        ";
                    dwReturn["VRKSOFORT"] = " ";
                    dwReturn["VRKAKKREDNR"] = "                    ";
                    dwReturn["VRKSACHBE"] = "        ";
                    dwReturn["VRKBENID"] = "        ";
                    dwReturn["VRKAUFTNR"] = "    ";
                    dwReturn["VRKSKTOP"] = "0";
                    dwReturn["VRKSKTOBP"] = "0";
                    dwReturn["VRKBELKRS"] = "   ";
                    dwReturn["VRKMWSTAB"] = "0";
                    dwReturn["VRKREGMWST"] = "0";
                    dwReturn["VRKREGMWSTAB"] = "0";
                    dwReturn["VRKHWAEHRSL"] = "RMB";
                    dwReturn["VRKHEUROKURS"] = "0";
                    dwReturn["VRKHEUROKURSVK"] = " ";
                    dwReturn["VRKFEUROKURS"] = "0";
                    dwReturn["VRKFEUROKURSVK"] = " ";
                    dwReturn["VRKNAME1"] = "                                        ";
                    dwReturn["VRKNAME2"] = "                                        ";
                    dwReturn["VRKSTRASSE1"] = "                                        ";
                    dwReturn["VRKSTRASSE2"] = "                                        ";
                    dwReturn["VRKLKZ"] = "US ";
                    dwReturn["VRKPLZPF"] = "            ";
                    dwReturn["VRKPOSTF"] = "               ";
                    dwReturn["VRKPLZ"] = "            ";
                    dwReturn["VRKORT"] = "                                        ";
                    dwReturn["VRKBZ"] = "  ";
                    dwReturn["VRKBZBEZ"] = "             ";
                    dwReturn["VRKCOUNTY"] = "    ";
                    dwReturn["VRKCITY"] = "    ";
                    dwReturn["VRKANSPNA"] = "                                        ";
                    dwReturn["VRKABZUGKZ"] = "N";
                    dwReturn["VRKABZUGDAT"] = "0";
                    dwReturn["VRKUEBKZ"] = " ";
                    dwReturn["VRKRLNR"] = "0";
                    dwReturn["VRKRLDAT"] = "0";
                    dwReturn["VRKARCHKZ"] = " ";
                    dwReturn["VRKARCHDAT"] = "0";
                    dwReturn["VRKARCHBEL"] = "0";
                    dwReturn["VRKFOB"] = " ";
                    dwReturn["VRKFOBAM"] = "0";
                    dwReturn["VRKGVRDICU"] = "0";
                    dwReturn["VRKGVRD"] = "0";
                    dwReturn["VRKRDOFFAM"] = "0";
                    dwReturn["VRKADINVNO"] = "            ";
                    dwReturn["VRKMENGE1"] = "0";
                    dwReturn["VRKMENGE2"] = "0";
                    dwReturn["VRKMENGE3"] = "0";
                    dwReturn["VRKMENGE4"] = "0";
                    dwReturn["VRKMWSTSL"] = "   ";
                    dwReturn["VRKWRAUM"] = "USA     ";
                    dwReturn["VRKZESSION"] = " ";
                    dwReturn["VRKOHNEREF"] = " ";
                    dwReturn["VRKVAEAKZ"] = "N";
                    dwReturn["VRKKREDKDNR"] = "00000000";
                    dwReturn["VRKCOVBETRAG"] = "0000000000";
                    dwReturn["VRKFAELLIGN"] = "0";
                    dwReturn["VRKNOPAYDAT"] = "0";
                    dwReturn["VRKNOKREDVERS"] = " ";
                    dwReturn["VRKKREDLIM1"] = "0";
                    dwReturn["VRKVERS1"] = "  ";
                    dwReturn["VRKVERS21"] = "  ";
                    dwReturn["VRKKREDLIM2"] = "0";
                    dwReturn["VRKVERS2"] = "  ";
                    dwReturn["VRKVERS22"] = "  ";
                    dwReturn["VRKKREDLIM3"] = "0";
                    dwReturn["VRKVERS3"] = "  ";
                    dwReturn["VRKVERS23"] = "  ";
                    dwReturn["VRKKREDLIM4"] = "0";
                    dwReturn["VRKVERS4"] = "  ";
                    dwReturn["VRKVERS24"] = "  ";
                    dwReturn["VRKKREDLIM5"] = "0";
                    dwReturn["VRKVERS5"] = "  ";
                    dwReturn["VRKVERS25"] = "  ";
                    dwReturn["VRKVERBNR"] = "        ";
                    dwReturn["VRKREU"] = "  ";
                    dwReturn["VRKMWSTID"] = "                    ";
                    dwReturn["VRKFILLER"] = "                                                                                ";
                    #endregion
                    break;
                case "JLT":
                    #region=========
                    dwReturn["VRKMANDANT"] = app.Mandant;
                    dwReturn["VRKRENR"] = "00000000";
                    dwReturn["VRKAENZL"] = "0";
                    dwReturn["VRKAENB"] = "        ";
                    dwReturn["VRKAEND"] = "0";
                    dwReturn["VRKNEUB"] = "        ";
                    dwReturn["VRKNEUD"] = "0";
                    dwReturn["VRKKUNDNR"] = "00000000";
                    dwReturn["VRKADRSL"] = "        ";
                    dwReturn["VRKREART"] = "SR";
                    dwReturn["VRKREDAT"] = "0";
                    dwReturn["VRKZAHLBED"] = "   ";
                    dwReturn["VRKVALUTA"] = "0";
                    dwReturn["VRKVALDAT"] = "0";
                    dwReturn["VRKWAEHRSL"] = "RMB";
                    dwReturn["VRKKURS"] = "10000";
                    dwReturn["VRKBETRAG"] = "1";
                    dwReturn["VRKWAWERT"] = "0";
                    dwReturn["VRKFRACHT"] = "0";
                    dwReturn["VRKVERSICH"] = "0";
                    dwReturn["VRKVERPKO"] = "0";
                    dwReturn["VRKZUAB"] = "0";
                    dwReturn["VRKGESWERTN"] = "0";
                    dwReturn["VRKMWST"] = "0";
                    dwReturn["VRKGESWERTB"] = "0";
                    dwReturn["VRKEKON"] = "        ";
                    dwReturn["VRKFIBUDAT"] = "0";
                    dwReturn["VRKFIBUBELEG"] = "0";
                    dwReturn["VRKFIBUKZ"] = "N";
                    dwReturn["VRKZAHLDAT"] = "0";
                    dwReturn["VRKZAHLBTR"] = "0";
                    dwReturn["VRKKOMPL"] = "N";
                    dwReturn["VRKFAELLIG"] = "0";
                    dwReturn["VRKVB"] = "2  ";
                    dwReturn["VRKSTUFE"] = " ";
                    dwReturn["VRKAUFTYP"] = "K";
                    dwReturn["VRKKZINLEXP"] = "E";
                    dwReturn["VRKLPOS"] = "000";
                    dwReturn["VRKDRKZ"] = " ";
                    dwReturn["VRKUMSATZ"] = "N";
                    dwReturn["VRKKUNDNRVK"] = "        ";
                    dwReturn["VRKADRSLVK"] = "        ";
                    dwReturn["VRKSOFORT"] = " ";
                    dwReturn["VRKAKKREDNR"] = "                    ";
                    dwReturn["VRKSACHBE"] = "        ";
                    dwReturn["VRKBENID"] = "        ";
                    dwReturn["VRKAUFTNR"] = "    ";
                    dwReturn["VRKSKTOP"] = "0";
                    dwReturn["VRKSKTOBP"] = "0";
                    dwReturn["VRKBELKRS"] = "   ";
                    dwReturn["VRKMWSTAB"] = "0";
                    dwReturn["VRKREGMWST"] = "0";
                    dwReturn["VRKREGMWSTAB"] = "0";
                    dwReturn["VRKHWAEHRSL"] = "RMB";
                    dwReturn["VRKHEUROKURS"] = "0";
                    dwReturn["VRKHEUROKURSVK"] = " ";
                    dwReturn["VRKFEUROKURS"] = "0";
                    dwReturn["VRKFEUROKURSVK"] = " ";
                    dwReturn["VRKNAME1"] = "                                        ";
                    dwReturn["VRKNAME2"] = "                                        ";
                    dwReturn["VRKSTRASSE1"] = "                                        ";
                    dwReturn["VRKSTRASSE2"] = "                                        ";
                    dwReturn["VRKLKZ"] = "US ";
                    dwReturn["VRKPLZPF"] = "            ";
                    dwReturn["VRKPOSTF"] = "               ";
                    dwReturn["VRKPLZ"] = "            ";
                    dwReturn["VRKORT"] = "                                        ";
                    dwReturn["VRKBZ"] = "  ";
                    dwReturn["VRKBZBEZ"] = "             ";
                    dwReturn["VRKCOUNTY"] = "    ";
                    dwReturn["VRKCITY"] = "    ";
                    dwReturn["VRKANSPNA"] = "                                        ";
                    dwReturn["VRKABZUGKZ"] = "N";
                    dwReturn["VRKABZUGDAT"] = "0";
                    dwReturn["VRKUEBKZ"] = " ";
                    dwReturn["VRKRLNR"] = "0";
                    dwReturn["VRKRLDAT"] = "0";
                    dwReturn["VRKARCHKZ"] = " ";
                    dwReturn["VRKARCHDAT"] = "0";
                    dwReturn["VRKARCHBEL"] = "0";
                    dwReturn["VRKFOB"] = " ";
                    dwReturn["VRKFOBAM"] = "0";
                    dwReturn["VRKGVRDICU"] = "0";
                    dwReturn["VRKGVRD"] = "0";
                    dwReturn["VRKRDOFFAM"] = "0";
                    dwReturn["VRKADINVNO"] = "            ";
                    dwReturn["VRKMENGE1"] = "0";
                    dwReturn["VRKMENGE2"] = "0";
                    dwReturn["VRKMENGE3"] = "0";
                    dwReturn["VRKMENGE4"] = "0";
                    dwReturn["VRKMWSTSL"] = "   ";
                    dwReturn["VRKWRAUM"] = "USA     ";
                    dwReturn["VRKZESSION"] = " ";
                    dwReturn["VRKOHNEREF"] = " ";
                    dwReturn["VRKVAEAKZ"] = "N";
                    dwReturn["VRKKREDKDNR"] = "00000000";
                    dwReturn["VRKCOVBETRAG"] = "0000000000";
                    dwReturn["VRKFAELLIGN"] = "0";
                    dwReturn["VRKNOPAYDAT"] = "0";
                    dwReturn["VRKNOKREDVERS"] = " ";
                    dwReturn["VRKKREDLIM1"] = "0";
                    dwReturn["VRKVERS1"] = "  ";
                    dwReturn["VRKVERS21"] = "  ";
                    dwReturn["VRKKREDLIM2"] = "0";
                    dwReturn["VRKVERS2"] = "  ";
                    dwReturn["VRKVERS22"] = "  ";
                    dwReturn["VRKKREDLIM3"] = "0";
                    dwReturn["VRKVERS3"] = "  ";
                    dwReturn["VRKVERS23"] = "  ";
                    dwReturn["VRKKREDLIM4"] = "0";
                    dwReturn["VRKVERS4"] = "  ";
                    dwReturn["VRKVERS24"] = "  ";
                    dwReturn["VRKKREDLIM5"] = "0";
                    dwReturn["VRKVERS5"] = "  ";
                    dwReturn["VRKVERS25"] = "  ";
                    dwReturn["VRKVERBNR"] = "        ";
                    dwReturn["VRKREU"] = "  ";
                    dwReturn["VRKMWSTID"] = "                    ";
                    dwReturn["VRKFILLER"] = "                                                                                ";
                    #endregion
                    break;
            }
        }

        public void InsertVRKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["VRKNEUB"] = app.User;
            dwData["VRKNEUD"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "YGR":
                case "SXN":
                case "JLT":
                case "TST":
                    or1.CommandText = "INSERT INTO VRKOPF ( VR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ICU:,:VRKGVRD:,:VRKRDOFFAM:,:VRKADINVNO:,:VRKMENGE1:,:VRKMENGE2:,:VRKMENGE3:,:VRKMENGE4:,:VRKMWSTSL:,:VRKWRAUM:,:VRKZESSION:,:VRKOHNEREF:,:VRKVAEAKZ:,:VRKKREDKDNR:,:VRKCOVBETRAG:,:VRKFAELLIGN:,:VRKNOPAYDAT:,:VRKNOKREDVERS:,:VRKKREDLIM1:,:VRKVERS1:,:VRKVERS21:,:VRKKREDLIM2:,:VRKVERS2:,:VRKVERS22:,:VRKKREDLIM3:,:VRKVERS3:,:VRKVERS23:,:VRKKREDLIM4:,:VRKVERS4:,:VRKVERS24:,:VRKKREDLIM5:,:VRKVERS5:,:VRKVERS25:,:VRKVERBNR:,:VRKREU:,:VRKMWSTID:,:VRKFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE 
            }

            Connect2Proxy(or1);
        }

        public DataSet QueryVRKOPF(DataRow dwData, int option = 1)
        { 
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    SResult = QVRK00(dwData);

                    break;
                case 1:
                    SResult = QVRK01(dwData);

                    break;
                case 2:
                    SResult = QVRK02(dwData);
                    break;
                case 3:
                    SResult = QVRK03(dwData);
                    break;
                case 4:

                    SResult = QVRK04(dwData);
                    break;
                case 5:
                    SResult = QVRK05(dwData);
                    break;
                case 6: 
                    SResult = QVRK06(dwData);
                    break;
                default:
                    break;
            }
          
            SResult.Tables[0].TableName = "VRKOPF";
            return SResult;
        }
        public DataSet QVRK00(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM VRKOPF WHERE  ROWNUM<2 ";
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM VRKOPF WHERE  "
                          + "  VRKMANDANT=:VRKMANDANT:  AND VRKRENR=:VRKRENR:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT DISTINCT VRKRENR FROM VRKOPF K JOIN VRPOS ON VRKMANDANT=VRPMANDANT AND K.VRKRENR=VRPRENR WHERE  "
                          + " VRKFIBUKZ='J' AND VRPMANDANT=:VRPMANDANT:  AND VRPAUFKRS=:VRPAUFKRS: AND VRPAUFLFD=:VRPAUFLFD:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM VRKOPF WHERE  "
                        + "  VRKMANDANT=:VRKMANDANT  AND VRKRENR=:VRKRENR";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK04(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT DISTINCT K.*,VRPAUFKRS,VRPAUFLFD,NVL(KDKUNDNA,' ') AS KDKUNDNA,NVL(LSLIEFNA,' ' ) AS LSLIEFNA"
                     + " FROM VRKOPF K JOIN VRPOS ON VRKMANDANT=VRPMANDANT AND K.VRKRENR=VRPRENR "
                     + " LEFT JOIN KDSTAMM ON KDMANDANT=VRKMANDANT AND VRPARTKUNDNR=KDKUNDNR"
                     + " LEFT JOIN LIEFDAT ON LSMANDANT=VRKMANDANT AND VRPVLIEFNR=LSLIEFNR"
                     + " WHERE VRKMANDANT=:VRKMANDANT:  "
                     + dwData["VRKZESSION"].ToString()//VRKZAHLBED     
                     + dwData["VRKZAHLBED"].ToString()//VRKZAHLBED
                     + dwData["VRKVERBNR"].ToString()//VRPAUFKRS
                     + dwData["VRKMWSTID"].ToString()//VRPAUFLFD
                     + dwData["VRKFILLER"].ToString()
                     + " ORDER BY VRKRENR,VRPAUFKRS,VRPAUFLFD ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK05(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT DISTINCT VRKMANDANT,VRKRENR,VRKZAHLBED,VRPAUFKRS,VRPAUFLFD,VRKGESWERTN,VRKWAWERT,VRKZUAB "
                          + " FROM VRKOPF K JOIN VRPOS ON VRKMANDANT=VRPMANDANT AND K.VRKRENR=VRPRENR "
                          + " WHERE VRKMANDANT=:VRKMANDANT:  "
                               + dwData["VRKZAHLBED"].ToString()//VRKZAHLBED
                              + dwData["VRKVERBNR"].ToString()//VRPAUFKRS
                              + dwData["VRKMWSTID"].ToString()//VRPAUFLFD
                              + dwData["VRKFILLER"].ToString()
                              + " ORDER BY VRKRENR,VRPAUFKRS,VRPAUFLFD ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QVRK06(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM VRKOPF WHERE  "
                                  + "  VRKMANDANT=:VRKMANDANT:  AND VRKVERBNR=:VRKVERBNR: AND VRKZESSION=:VRKZESSION:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }

        public void DeleteVRKOPF(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {

                case 0:
                    or1.CommandText = "DELETE FROM VRKOPF WHERE VRKMANDANT=:VRKMANDANT:  AND VRKZESSION=:VRKZESSION:"
                        + dwData["VRKVERBNR"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
                    break;
                case 1:
                    or1.CommandText = "DELETE FROM VRKOPF WHERE VRKMANDANT=:VRKMANDANT:  AND VRKRENR=:VRKRENR:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    break;
                case 2:
                    or1.CommandText = "DELETE FROM VRKOPF WHERE VRKMANDANT=:VRKMANDANT:  ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateVRKOPF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            if (dwData != null)
            {
                dwData["VRKAENB"] = app.User;
                dwData["VRKAEND"] = date;
            }
            if (option == 0)
            {
                switch (app.company)
                {
                    case "YGR":
                    case "YCC":
                    case "JLT":
                    default:
                        option = 1;
                        break;
                }
            }
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE VRKOPF SET VRKMANDANT=:VRKMANDANT:,VRKRENR=:VRKRENR:,VRKAENZL=:VRKAENZL:,VRKAENB=:VRKAENB:,VRKAEND=:VRKAEND:,VRKNEUB=:VRKNEUB:,VRKNEUD=:VRKNEUD:,VRKKUNDNR=:VRKKUNDNR:,VRKADRSL=:VRKADRSL:,VRKREART=:VRKREART:,VRKREDAT=:VRKREDAT:,VRKZAHLBED=:VRKZAHLBED:,VRKVALUTA=:VRKVALUTA:,VRKVALDAT=:VRKVALDAT:,VRKWAEHRSL=:VRKWAEHRSL:,VRKKURS=:VRKKURS:,VRKBETRAG=:VRKBETRAG:,VRKWAWERT=:VRKWAWERT:,VRKFRACHT=:VRKFRACHT:,VRKVERSICH=:VRKVERSICH:,VRKVERPKO=:VRKVERPKO:,VRKZUAB=:VRKZUAB:,VRKGESWERTN=:VRKGESWERTN:,V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A=:VRKANSPNA:,VRKABZUGKZ=:VRKABZUGKZ:,VRKABZUGDAT=:VRKABZUGDAT:,VRKUEBKZ=:VRKUEBKZ:,VRKRLNR=:VRKRLNR:,VRKRLDAT=:VRKRLDAT:,VRKARCHKZ=:VRKARCHKZ:,VRKARCHDAT=:VRKARCHDAT:,VRKARCHBEL=:VRKARCHBEL:,VRKFOB=:VRKFOB:,VRKFOBAM=:VRKFOBAM:,VRKGVRDICU=:VRKGVRDICU:,VRKGVRD=:VRKGVRD:,VRKRDOFFAM=:VRKRDOFFAM:,VRKADINVNO=:VRKADINVNO:,VRKMENGE1=:VRKMENGE1:,VRKMENGE2=:VRKMENGE2:,VRKMENGE3=:VRKMENGE3:,VRKMENGE4=:VRKMENGE4:,VRKMWSTSL=:VRKMWSTSL:,VRKWRAUM=:VRKWRAUM:,VRKZESSION=:VRKZESSION:,VRKOHNEREF=:VRKOHNEREF:,VRKVAEAKZ=:VRKVAEAKZ:,VRKKREDKDNR=:VRKKREDKDNR:,VRKCOVBETRAG=:VRKCOVBETRAG:,VRKFAELLIGN=:VRKFAELLIGN:,VRKNOPAYDAT=:VRKNOPAYDAT:,VRKNOKREDVERS=:VRKNOKREDVERS:,VRKKREDLIM1=:VRKKREDLIM1:,VRKVERS1=:VRKVERS1:,VRKVERS21=:VRKVERS21:,VRKKREDLIM2=:VRKKREDLIM2:,VRKVERS2=:VRKVERS2:,VRKVERS22=:VRKVERS22:,VRKKREDLIM3=:VRKKREDLIM3:,VRKVERS3=:VRKVERS3:,VRKVERS23=:VRKVERS23:,VRKKREDLIM4=:VRKKREDLIM4:,VRKVERS4=:VRKVERS4:,VRKVERS24=:VRKVERS24:,VRKKREDLIM5=:VRKKREDLIM5:,VRKVERS5=:VRKVERS5:,VRKVERS25=:VRKVERS25:,VRKVERBNR=:VRKVERBNR:,VRKREU=:VRKREU:,VRKMWSTID=:VRKMWSTID:,VRKFILLER=:VRKFILLER:"
                        + " WHERE  VRKMANDANT=:VRKMANDANT: AND VRKRENR=:VRKRENR: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    or1.CommandText = "UPDATE VRKOPF SET VRKZAHLBED=:VRKZAHLBED:,VRKKUNDNR=:VRKKUNDNR:"
                        + " WHERE  VRKMANDANT=:VRKMANDANT: AND VRKRENR=:VRKRENR: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
